package com.hxd.mall.module.account.login

import com.hxd.mall.constant.HxdConstantsAccount
import com.hxd.mall.network.base.BaseRequest
import com.hxd.mall.network.service.ManagerFunctionApi.mIAccountFunctionApi
import com.hxd.mall.utils.open.ToastUtil
import javax.inject.Inject

/**
 * 登录Presenter
 * Created by qishuai on 2018/7/29.
 */
class LoginPresenter @Inject constructor(var mView: ILoginView) : ILoginPresenter {
    override fun getflag() {
        BaseRequest.request(mIAccountFunctionApi.flag, mView, {
            mView?.fetchFlag(it)
        }, {
            it.msg?.let { it1 -> ToastUtil.showToast(it1) }
        })

    }

    override fun getData(isRefresh: Boolean) {

    }

    override fun isRegistered(phoneNumber: String,type:Int) {
        BaseRequest.request(mIAccountFunctionApi.isRegister(phoneNumber), mView, {
            if (it?.data?.isBindWx==true && type != HxdConstantsAccount.mobile_register){
                //如果绑定过微信 并且是从微信登录渠道来此需要提示用户换个手机号
                ToastUtil.showToast("该手机已经绑定过微信,请换个手机号绑定微信")
                return@request
            }
            mView.isRegister(it?.data?.success)
        }, {
            it.msg?.let { it1 -> ToastUtil.showToast(it1) }
        })
    }
}